package com.hsd.framework.util;


import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;

@Slf4j
public class YamlConfigurerUtil {

    //    private static Properties ymlProperties = null;
    private static Environment ymlProperties;

    //    public YamlConfigurerUtil(Properties properties) {
    //        ymlProperties = properties;
    //    }
    public static void setYmlProperties(Environment ymlProperties) {
        YamlConfigurerUtil.ymlProperties = ymlProperties;
    }

    public static String getStrYmlVal(String key) {//1:加载配置文件
//        if (ymlProperties == null) {
//            YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
//            yaml.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE);
//            yaml.setResources(new ClassPathResource("application.yml"));
//            yaml.setSingleton(true);
//            yaml.afterPropertiesSet();
//            ymlProperties = yaml.getObject();
//        }
        return ymlProperties.getProperty(key);
    }

    public static Integer getIntegerYmlVal(String key) {
        return Integer.valueOf(ymlProperties.getProperty(key));
    }

    public static void main(String[] args) {
        System.out.println(getStrYmlVal("file-server.upload").replace("${file-server.root-folder}", getStrYmlVal("file-server.root-folder")));
        System.out.println(getStrYmlVal("beetl.delimiter_statement_start"));
        System.out.println(getStrYmlVal("beetl.delimiter_statement_end"));

        System.out.println(YamlConfigurerUtil.getStrYmlVal("beetl.delimiter_placeholder_start"));
        System.out.println(YamlConfigurerUtil.getStrYmlVal("beetl.delimiter_placeholder_end"));
        System.out.println(YamlConfigurerUtil.getStrYmlVal("beetl.delimiter_statement_start"));
        System.out.println(YamlConfigurerUtil.getStrYmlVal("beetl.delimiter_statement_end"));
        System.out.println(YamlConfigurerUtil.getStrYmlVal("beetl.cfg_package"));
    }

}